package org.pushforward.iwillsurvive.helpers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Error404Handler - The Bad Request
 */
@WebServlet(description = "Constructs the 400 Error", urlPatterns = { "/400" })
public class Error400Handler extends HttpServlet 
{
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Error400Handler() 
    {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, 
						 HttpServletResponse response) 
						 throws ServletException, IOException 
	{
		String message = request.getParameter("ErrorMessage");

		String standard400Message = "It seems that you have done something wrong.<br><br>\n" +
									"Perhaps you should check those parameters again.<br>\n";

		PageBuilder.GenerateErrorPage(response, "iWillSurvive 400 Error Page",
									  "Error 400 - Bad Request", standard400Message, message, 400);	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		doGet(request, response);
	}

}
